package com.abs.orm.convert;

import java.util.ArrayList;
import java.util.List;

import com.abs.orm.model.file.ActionApplicationContextFileModel;
import com.abs.orm.model.file.ActionFileModel;
import com.abs.orm.model.file.DaoFileModel;
import com.abs.orm.model.file.DaoImplFileModel;
import com.abs.orm.model.file.HbmFileModel;
import com.abs.orm.model.file.ModelFileModel;
import com.abs.orm.model.file.ServiceFileModel;
import com.abs.orm.model.file.ServiceImplFileModel;
import com.abs.orm.model.file.SpringApplicationContextFileModel;
import com.abs.orm.model.file.config.ActionConfigModel;
import com.abs.orm.model.file.config.DaoConfigModel;
import com.abs.orm.model.file.config.DaoImplConfigModel;
import com.abs.orm.model.file.config.ModelConfigModel;
import com.abs.orm.model.file.config.ServiceConfigModel;
import com.abs.orm.model.file.config.ServiceImplConfigModel;
import com.abs.orm.util.StringUtil;
import com.ads.orm.db.model.Column;
import com.ads.orm.db.model.Table;
import com.ads.orm.model.j.JField;

public class ConvertImpl implements Convert {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3169874365211653972L;

	public ModelFileModel convert(Table table, ModelConfigModel config) {
		ModelFileModel model = new ModelFileModel();
		model.setExtend(config.getExtend());
		model.setFileName(StringUtil.toClassName(table.getTableName()));
		model.setImpls(config.getImpls());
		model.setImports(config.getImports());
		model.setPack(config.getPack());
		model.setSuffix(config.getSuffix());
		JField field = null;
		List<JField> fields = new ArrayList<JField>();
		for (Column c : table.getColumns()) {
			field = new JField();
			field.setClazz(c.getColumnClassName());
			field.setName(StringUtil.toAttriName(c.getColumnName()));
			fields.add(field);
		}
		model.setJFields(fields);
		return model;
	}

	public DaoFileModel convert(Table table, ModelFileModel model,
			DaoConfigModel config) {
		DaoFileModel dao = new DaoFileModel();
		dao.setExtend(config.getExtend().replaceAll("<T", model.getFileName())
				.replaceAll("PK>", table.getPKColumn().getColumnName()));
		dao.setSuffix(config.getSuffix());
		dao.setFileName(model.getFileName() + dao.getSuffix());
		dao.setImpls(config.getImpls());
		dao.setImports(config.getImports());
		dao.setPack(config.getPack());
		dao.getImports().add(model.getPack() + "." + model.getFileName());
		return dao;
	}

	public DaoImplFileModel convert(Table table, ModelFileModel model,
			DaoFileModel dao, DaoImplConfigModel config) {
		DaoImplFileModel daoImpl = new DaoImplFileModel();
		daoImpl.setExtend(config.getExtend()
				.replaceAll("<T", model.getFileName())
				.replaceAll("PK>", table.getPKColumn().getColumnName()));
		daoImpl.setSuffix(config.getSuffix());
		daoImpl.setFileName(model.getFileName() + dao.getSuffix()
				+ daoImpl.getSuffix());
		daoImpl.setImpls(config.getImpls());
		daoImpl.setImports(config.getImports());
		daoImpl.setPack(config.getPack());
		daoImpl.getImports().add(model.getPack() + "." + model.getFileName());
		daoImpl.getImports().add(dao.getPack() + "." + dao.getFileName());
		return daoImpl;
	}

	public ServiceFileModel convert(ModelFileModel model, DaoFileModel dao,
			ServiceConfigModel config) {
		// TODO Auto-generated method stub
		return null;
	}

	public ServiceImplFileModel convert(ModelFileModel model, DaoFileModel dao,
			ServiceFileModel service, ServiceImplConfigModel config) {
		// TODO Auto-generated method stub
		return null;
	}

	public ActionFileModel convert(ModelFileModel model, DaoFileModel dao,
			ServiceFileModel service, ActionConfigModel config) {
		// TODO Auto-generated method stub
		return null;
	}

	public HbmFileModel convert(Table table, ModelFileModel model) {
		// TODO Auto-generated method stub
		return null;
	}

	public SpringApplicationContextFileModel convert(DaoFileModel dao,
			DaoImplFileModel daoImpl) {
		// TODO Auto-generated method stub
		return null;
	}

	public SpringApplicationContextFileModel convert(ServiceFileModel service,
			ServiceImplFileModel serviceImpl) {
		// TODO Auto-generated method stub
		return null;
	}

	public ActionApplicationContextFileModel convert(DaoFileModel dao,
			DaoImplFileModel daoImpl, ServiceFileModel service,
			ServiceImplFileModel serviceImpl) {
		// TODO Auto-generated method stub
		return null;
	}

}
